﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace StudentOrganizer
{
    class StudentOrganizer
    {
        static void Main(string[] args)
        {
            FileStream file = new FileStream("../../Students.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            using (file)
            {
                int offset = 0;
                Student ivan = new Student("Ivan", "Petrov", 111206);
                Add(ivan, file,ref offset);
                Student georgi = new Student("Georgi", "Ivanov", 111086);
                Add(georgi, file, ref offset);
                Student stan = new Student("Stanislav", "Savov", 121486);
                Add(stan, file, ref offset);
                PrintAll(file);
            }
        }

        private static void Add(Student ivan, FileStream file, ref int offset)
        {
            Byte[] studentBytes = ivan.GetBytes();
            file.Write(studentBytes, offset, studentBytes.Length);
        }

        private static void PrintAll(FileStream file)
        {
            while (true)
            {
                byte[] buf = new byte[124096];
                int bytesRead = file.Read(buf, 0, buf.Length);
                if (bytesRead == 0)
                {
                    break;
                }
                Console.WriteLine(bytesRead);
            }
        }

        private static void Delete(int facultyNumber)
        { }
    }
}
